#include<iostream>
#include<algorithm>
#include<stdio.h>

using namespace std;

typedef struct Node* Tree;
struct Node {
    int key;
    Tree left;
    Tree right;
    int height;
    Node(int value):key(value),left(NULL),right(NULL),height(1) {};
};

int Height(Tree x);
Tree AVLInsert(Tree x, int value);
Tree LLrotate(Tree P);
Tree LRrotate(Tree P);
Tree RRrotate(Tree P);
Tree RLrotate(Tree P);

int Height(Tree x) 
{
    if(x==NULL) return 0;
    else return x->height;
}
Tree AVLInsert(Tree x, int value)
{
    if(x==NULL) return new Node(value);
    if(value==x->key) return x;
    else if(value<x->key) {
        x->left = AVLInsert(x->left,value);
        if(Height(x->left)-Height(x->right)>=2) {
            if(Height(x->left->left)>Height(x->left->right)) {
                x = LLrotate(x);
            }
            else x = LRrotate(x);
        }
    }
    else {
        x->right = AVLInsert(x->right,value);
        if(Height(x->right)-Height(x->left)>=2) {
            if(Height(x->right->right)>Height(x->right->left)) {
                x = RRrotate(x);
            }
            else x = RLrotate(x);
        }
    } 
    x->height = std::max(Height(x->left),Height(x->right))+1;
    return x;
}

Tree LLrotate(Tree P) {
    Tree S = P->left;
    P->left = S->right;
    S->right = P;
    P->height = std::max(Height(P->left),Height(P->right))+1;
    S->height = std::max(Height(S->left),Height(S->right))+1;
    return S;
}
Tree LRrotate(Tree P) {
    P->left = RRrotate(P->left);
    return LLrotate(P);
}
Tree RRrotate(Tree P) {
    Tree S = P->right;
    P->right = S->left;
    S->left = P;
    P->height = std::max(Height(P->left),Height(P->right))+1;
    S->height = std::max(Height(S->left),Height(S->right))+1;
    return S;
}
Tree RLrotate(Tree P) {
    P->right = LLrotate(P->right);
    return RRrotate(P);
}
int main()
{
    int N;
    cin>>N;
    Tree root = NULL;
    for(int i = 0; i < N;i++) {
        int temp;
        cin>>temp;
        root = AVLInsert(root,temp);
    }
    cout<<root->key<<endl;
}